package com.jeff.tianti.controller.channel;

import com.jeff.tianti.cms.entity.MessageInformCms;
import com.jeff.tianti.cms.entity.MessageInteraction;
import com.jeff.tianti.cms.service.MessageInformCmsService;
import com.jeff.tianti.cms.service.MessageInteractionService;
import com.jeff.tianti.common.dto.AjaxResult;
import com.jeff.tianti.common.entity.BaseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/channel/message")//江苏频道_留言互动模块
@CrossOrigin(maxAge = 3600)
public class MessageInteractionController {
    @Autowired
    private MessageInformCmsService messageInformCmsService;

    /**
     * @return [map:key]0->背景图 1->关于我们 2->联系我们 3->隐私条款
     * @Ceator:liuYI
     * @Describe:获取江苏频道_留言互动页面数据
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public AjaxResult findAll() {
        List<MessageInformCms> messageInformCms = messageInformCmsService.queryMessageInformCmsList(null);
        Map<String, Set<String>> map = new HashMap<>();
        Set<String> set = new HashSet<>();
        map.put("0", set);
        map.put("1", set);
        map.put("2", set);
        map.put("3", set);
//        Map<String, Set<String>> resultMap = personList.stream().collect(Collectors.groupingBy(Person::getSex, Collectors.mapping(Person::getName, Collectors.toSet())));

        Map<String, Set<String>> collect = messageInformCms.stream().collect(Collectors.groupingBy(MessageInformCms::getState, Collectors.mapping(MessageInformCms::getContent, Collectors.toSet())));
        map.putAll(collect);
        return AjaxResult.setSuccessData(map);
    }

    @Autowired
    private MessageInteractionService messageInteractionService;
    /**
     * @Ceator:liuYI
     * @Describe:留言互动_用户留言
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public AjaxResult guestbook(@RequestBody MessageInteraction mes) {
        mes.setAuditFlag(BaseEntity.AUDIT_FLAG_NOT);
        messageInteractionService.save(mes);
        return AjaxResult.setSuccessData(null);
    }
}
